package captcha

import (
	. "Go-Easy/pkg/config"
	captcha "github.com/mojocn/base64Captcha"
)
//生成验证码图片

var store = captcha.DefaultMemStore

func NewDriver() *captcha.DriverString {
	driver := new(captcha.DriverString)
	driver.Height = Captcha.Height
	driver.Width = Captcha.Width
	driver.NoiseCount = Captcha.NoiseCount
	driver.ShowLineOptions = captcha.OptionShowSlimeLine
	driver.Length = Captcha.Length
	driver.Source = Captcha.Source
	driver.Fonts = []string{"wqy-microhei.ttc"}
	return driver
}

func GenerateCaptcha() (digits string, base64 string, err error) {
	c := captcha.NewCaptcha(NewDriver(), store)
	if id, b64s, err := c.Generate(); err == nil {
		digits := store.Get(id, true)
		return digits, b64s, nil
	} else {
		return "", "", err
	}
}
